//
//  UIButton+Bootstrap.m
//  UIButton+Bootstrap
//
//  Created by Oskur on 2013-09-29.
//  Copyright (c) 2013 Oskar Groth. All rights reserved.
//
#import "UIButton+Bootstrap.h"
#import <QuartzCore/QuartzCore.h>
#import "GWMacro.h"

@implementation UIButton (Bootstrap)
-(void)sendMessageStyle
{
    self.layer.borderWidth = 0.5;
    self.layer.cornerRadius = 4.0;
    self.layer.masksToBounds = YES;
    [self setAdjustsImageWhenHighlighted:NO];
    self.layer.borderColor = [[UIColor colorWithRed:0.541 green:0.548 blue:0.553 alpha:1.000] CGColor];
    self.backgroundColor = [UIColor clearColor];
    [self setTitleColor:[UIColor colorWithRed:0.541 green:0.548 blue:0.553 alpha:1.000] forState:UIControlStateNormal];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:0.541 green:0.548 blue:0.553 alpha:1.000]] forState:UIControlStateHighlighted];
}

-(void)sendMessageClearStyle
{
    self.layer.borderWidth = 0.5;
    self.layer.cornerRadius = 4.0;
    self.layer.masksToBounds = YES;
    [self setAdjustsImageWhenHighlighted:NO];
    self.layer.borderColor = [ios7BlueColor CGColor];
    self.backgroundColor = [UIColor whiteColor];
    [self setTitleColor:ios7BlueColor forState:UIControlStateNormal];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]] forState:UIControlStateHighlighted];
}

/**
 *  用户标签选择
 */
-(void)labelphotoStyle
{
    self.layer.borderWidth = 0.5;
    self.layer.masksToBounds = YES;
//    [self setAdjustsImageWhenHighlighted:NO];
    self.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    self.backgroundColor = [UIColor whiteColor];
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
}

-(void)bootstrapStyle{
    self.layer.borderWidth = 0.5;
    self.layer.cornerRadius = 4.0;
    self.layer.masksToBounds = YES;
    [self setAdjustsImageWhenHighlighted:NO];
    self.layer.borderColor = [ios7BlueColor CGColor];

    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //[self.titleLabel setFont:[UIFont fontWithName:@"FontAwesome" size:self.titleLabel.font.pointSize]];
}

-(void)defaultStyle{
    [self bootstrapStyle];
//    self.enabled = NO;
    [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//  [self setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    self.backgroundColor = [UIColor whiteColor];
    self.layer.borderColor = [[UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:0.7] CGColor];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1]] forState:UIControlStateHighlighted];
}

-(void)primaryStyle{
    [self bootstrapStyle];
    self.backgroundColor = [UIColor colorWithRed:66/255.0 green:139/255.0 blue:202/255.0 alpha:1];
    self.layer.borderColor = [[UIColor colorWithRed:53/255.0 green:126/255.0 blue:189/255.0 alpha:1] CGColor];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:51/255.0 green:119/255.0 blue:172/255.0 alpha:1]] forState:UIControlStateHighlighted];
}

-(void)successStyle{
    [self bootstrapStyle];
    self.backgroundColor = [UIColor colorWithRed:92/255.0 green:184/255.0 blue:92/255.0 alpha:1];
    self.layer.borderColor = [[UIColor colorWithRed:76/255.0 green:174/255.0 blue:76/255.0 alpha:1] CGColor];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:69/255.0 green:164/255.0 blue:84/255.0 alpha:1]] forState:UIControlStateHighlighted];
}



-(void)infoStyle{
    [self bootstrapStyle];
    /*self.backgroundColor = [UIColor colorWithRed:91/255.0 green:192/255.0 blue:222/255.0 alpha:1];
    self.layer.borderColor = [[UIColor colorWithRed:70/255.0 green:184/255.0 blue:218/255.0 alpha:1] CGColor];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]] forState:UIControlStateHighlighted];
    
    self.backgroundColor = ios7BlueColor;
    self.layer.borderColor = [ios7BlueColor CGColor];
     */
    
    self.backgroundColor = [UIColor colorWithRed:29/255.0 green:211/255.0 blue:4/255.0 alpha:1];
    self.layer.borderColor = [UIColor colorWithRed:29/255.0 green:211/255.0 blue:4/255.0 alpha:1].CGColor;
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:59/255.0  green:199.0/255.0 blue:10/255.0 alpha:1.0]] forState:UIControlStateHighlighted];
    
    
}


-(void)MDinfoStyle{
    
    [self setAdjustsImageWhenHighlighted:NO];
    self.layer.borderColor = [ios7BlueColor CGColor];
    
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    self.backgroundColor = [UIColor colorWithRed:91/255.0 green:192/255.0 blue:222/255.0 alpha:1];
    self.layer.borderColor = [[UIColor colorWithRed:70/255.0 green:184/255.0 blue:218/255.0 alpha:1] CGColor];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]] forState:UIControlStateHighlighted];
    
    self.backgroundColor = ios7BlueColor;
    self.layer.borderColor = [ios7BlueColor CGColor];
}


-(void)MDpayStyle{
    
    [self setAdjustsImageWhenHighlighted:NO];
    
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:20.0f];
    [self setBackgroundImage:[UIImage imageNamed:@"btn_button_normal"] forState:UIControlStateNormal];
    [self setBackgroundImage:[UIImage imageNamed:@"btn_button_press"] forState:UIControlStateHighlighted];
    
}

-(void)MDCancelStyle{
    
    [self setAdjustsImageWhenHighlighted:NO];
    
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:20.0f];
    [self setBackgroundImage:[UIImage imageNamed:@"btn_cancle_normal"] forState:UIControlStateNormal];
//    [self setBackgroundImage:[UIImage imageNamed:@"btn_cancle_normal"] forState:UIControlStateHighlighted];    
}

-(void)MDClearColorInfoStyle{
    self.layer.borderWidth = 0.5;
    self.layer.cornerRadius = 4.0;
    self.layer.masksToBounds = YES;
    [self setAdjustsImageWhenHighlighted:NO];
    self.layer.borderColor = [ios7BlueColor CGColor];
    self.backgroundColor = [UIColor clearColor];
    [self setTitleColor:ios7BlueColor forState:UIControlStateNormal];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]] forState:UIControlStateHighlighted];
    
    self.layer.borderColor = [ios7BlueColor CGColor];
}

-(void)MDClearColorInfoStyle:(UIColor * )color
{
//    self.layer.borderWidth = 0.5;
//    self.layer.cornerRadius = 4.0;
//    self.layer.masksToBounds = YES;
    [self setAdjustsImageWhenHighlighted:NO];
    self.layer.borderColor = [color CGColor];
    self.backgroundColor = [UIColor clearColor];
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self setBackgroundImage:[self buttonImageFromColor:color] forState:UIControlStateNormal];
    
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]] forState:UIControlStateHighlighted];
    
    self.layer.borderColor = [color CGColor];
}


-(void)warningStyle{
    [self bootstrapStyle];
    self.backgroundColor = [UIColor colorWithRed:240/255.0 green:173/255.0 blue:78/255.0 alpha:1];
    self.layer.borderColor = [[UIColor colorWithRed:238/255.0 green:162/255.0 blue:54/255.0 alpha:1] CGColor];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:237/255.0 green:155/255.0 blue:67/255.0 alpha:1]] forState:UIControlStateHighlighted];
}

-(void)dangerStyle{
    [self bootstrapStyle];
    //[UIColor colorWithPatternImage:[UIImage imageNamed:@"med-name-bg-0"]];
    self.backgroundColor =  [UIColor colorWithRed:217/255.0 green:83/255.0 blue:79/255.0 alpha:1];
    self.layer.borderColor = [[UIColor colorWithRed:212/255.0 green:63/255.0 blue:58/255.0 alpha:1] CGColor];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:210/255.0 green:48/255.0 blue:51/255.0 alpha:1]] forState:UIControlStateHighlighted];
    [self setBackgroundImage:[self buttonImageFromColor:[UIColor colorWithRed:210/255.0 green:50/255.0 blue:57/255.0 alpha:1]] forState:UIControlStateHighlighted];
}

- (UIImage *) buttonImageFromColor:(UIColor *)color {
    CGRect rect = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

@end
